package cn.iocoder.yudao.module.wine.controller.admin.stockinfo;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.wine.controller.admin.stockinfo.vo.*;
import cn.iocoder.yudao.module.wine.dal.dataobject.stockinfo.StockInfoDO;
import cn.iocoder.yudao.module.wine.service.stockinfo.StockInfoService;

@Tag(name = "管理后台 - 出入库信息")
@RestController
@RequestMapping("/wine/stock-info")
@Validated
public class StockInfoController {

    @Resource
    private StockInfoService stockInfoService;

    @PostMapping("/create")
    @Operation(summary = "创建出入库信息")
    @PreAuthorize("@ss.hasPermission('wine:stock-info:create')")
    public CommonResult<Long> createStockInfo(@Valid @RequestBody StockInfoSaveReqVO createReqVO) {
        return success(stockInfoService.createStockInfo(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新出入库信息")
    @PreAuthorize("@ss.hasPermission('wine:stock-info:update')")
    public CommonResult<Boolean> updateStockInfo(@Valid @RequestBody StockInfoSaveReqVO updateReqVO) {
        stockInfoService.updateStockInfo(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除出入库信息")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('wine:stock-info:delete')")
    public CommonResult<Boolean> deleteStockInfo(@RequestParam("id") Long id) {
        stockInfoService.deleteStockInfo(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得出入库信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('wine:stock-info:query')")
    public CommonResult<StockInfoRespVO> getStockInfo(@RequestParam("id") Long id) {
        StockInfoDO stockInfo = stockInfoService.getStockInfo(id);
        return success(BeanUtils.toBean(stockInfo, StockInfoRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得出入库信息分页")
    @PreAuthorize("@ss.hasPermission('wine:stock-info:query')")
    public CommonResult<PageResult<StockInfoRespVO>> getStockInfoPage(@Valid StockInfoPageReqVO pageReqVO) {
        PageResult<StockInfoRespVO> pageResult = stockInfoService.getStockInfoPage(pageReqVO);
        return success(pageResult);
    }

//    @GetMapping("/export-excel")
//    @Operation(summary = "导出出入库信息 Excel")
//    @PreAuthorize("@ss.hasPermission('wine:stock-info:export')")
//    @OperateLog(type = EXPORT)
//    public void exportStockInfoExcel(@Valid StockInfoPageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<StockInfoDO> list = stockInfoService.getStockInfoPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "出入库信息.xls", "数据", StockInfoRespVO.class,
//                        BeanUtils.toBean(list, StockInfoRespVO.class));
//    }

}
